﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Factory;

namespace XProject.DataVisit.Model
{
    public class Equipment:IProjectModel
    {
        public virtual Guid PID { get; set; }
        /// <summary>
        /// 设备名称
        /// </summary>
        public virtual string EquipmentName { get; set; }
        /// <summary>
        /// 设备唯一识别码
        /// </summary>
        public virtual string EquipmentCode { get; set; }
        /// <summary>
        /// 设备IP地址
        /// </summary>
        public virtual string EquipmentIP { get; set; }

        /// <summary>
        /// 所在地区
        /// </summary>
        public virtual Guid AreaID { get; set; }

        /// <summary>
        /// 负责人ID
        /// </summary>
        public virtual Guid PersonID { get; set; }

        /// <summary>
        /// 发布人ID
        /// </summary>
        public virtual Guid Creater { get; set; }

        public virtual DateTime LastUpdate { get; set; }

        public virtual string NTime { get {
            return LastUpdate.ToString("yyyy-MM-dd");
        } }


        /// <summary>
        /// 设备负责人
        /// </summary>
        public virtual UserInfo EquipmentChargePerson
        {
            get
            {
                if (PersonID != Guid.Empty)
                    return DaoFactory.UserInfoDao.GetById(PersonID);
                return null;
            }
        }

        #region 重写Hash和Equals
        public override int GetHashCode()
        {
            return PID.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            var temp = obj as Equipment;
            if (temp == null) return false;
            return temp.PID == this.PID;
        }
        #endregion
    }
}
